package exercises;

import java.util.*;

/**
 * 输入一个字符串，统计字符串中每个字符出现的次数并输出
 */


public class Demo03 {
    public static void main(String[] args) {
        System.out.println(count(input()));
////        String[] str = {"a", "g", "g","j", "h", "h"};
////        System.out.println(count(str));
    }

    public static Map count(String[] str) {
        Map map = new HashMap();
        int count;
        for (int i = 0; i < str.length; i++) {
            count = 0;
            for (int j = 0; j < str.length; j++) {
                if (str[i].equals(str[j])) {
                    count++;
                }
            }
            map.put(str[i],count);
        }
        return map;
    }

    public static String[] input(){
        Scanner sc = new Scanner(System.in);
        System.out.println("输入一个字符串：");
        String str = sc.nextLine();
        String[] str1 = str.split("");
        System.out.println(Arrays.toString(str1));
        return str1;
    }

}

